<script setup>
import { defineProps, defineEmits ,ref,watch} from 'vue'

const props = defineProps({
  // 新增按钮显示
  addBtnFlag: {
    type: Boolean,
    default: true
  },
  // 新增权限
  addHasPermi: {
    type: Array,
    default: []
  },
  // 修改按钮显示
  updateBtnFlag: {
    type: Boolean,
    default: true
  },
  // 修改权限
  updateHasPermi: {
    type: Array,
    default: []
  },
  // 删除按钮显示
  deleteBtnFlag: {
    type: Boolean,
    default: true
  },
  // 删除权限
  deleteHasPermi: {
    type: Array,
    default: []
  },
  // 导出按钮显示
  exportBtnFlag: {
    type: Boolean,
    default: true
  },
  // 导出权限
  exportHasPermi: {
    type: Array,
    default: []
  },
  // 修改禁用
  single: {
    type: Boolean,
    default: true
  },
  // 删除禁用
  multiple: {
    type: Boolean,
    default: true
  },
})

const emit = defineEmits(['handleAdd', 'handleUpdate', 'handleDelete', 'handleExport', 'showSearch', 'getList'])
const showSearch = ref(true)
// 新增
const handleAdd = () => {
  emit('handleAdd')
}
// 修改
const handleUpdate = () => {
  emit('handleUpdate')
}
// 删除
const handleDelete = () => {
  emit('handleDelete')
}
// 导出
const handleExport = () => {
  emit('handleExport')
}

//   显示隐藏搜索
watch(() => showSearch.value, (newVal, oldVal) => {
  emit('showSearch')
})

//   获取最新的数据
const getList = () => {
  emit('getList')
}
</script>

<template>
  <el-row :gutter="10" class="mb8">
    <el-col :span="1.5" v-if="props.addBtnFlag">
      <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="props.addHasPermi"
      >新增
      </el-button>
    </el-col>
    <el-col :span="1.5" v-if="props.updateBtnFlag">
      <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="props.single"
          @click="handleUpdate"
          v-hasPermi="props.updateHasPermi"
      >修改
      </el-button>
    </el-col>
    <el-col :span="1.5" v-if="props.deleteBtnFlag">
      <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="props.multiple"
          @click="handleDelete"
          v-hasPermi="props.deleteHasPermi"
      >删除
      </el-button>
    </el-col>
    <el-col :span="1.5" v-if="props.exportBtnFlag">
      <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="props.exportHasPermi"
      >导出
      </el-button>
    </el-col>

    <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  </el-row>
</template>

<style scoped lang="scss">

</style>